% close all
% 
% cellnr = 54;
% grey=[0.6 0.6 0.6];
% shift = floor(size(ROIs(cellnr).segments,1)/2);
% figure
% title(['Cell nr. ' num2str(cellnr)])
% hold on
% for ind = 1:size(ROIs(cellnr).segments,2)
%     plot([-shift:shift],ROIs(cellnr).segments(:,ind),'color',grey,'linewidth',1)
% end
% STA(1:size(ROIs(cellnr).segments,1)) = mean(ROIs(cellnr).segments(:,:),2);
% plot([-shift:shift],STA,'k','linewidth',3)
% plot([-shift:shift],mean(ROIs(cellnr).segments')+std(ROIs(cellnr).segments')/9,'k')
% plot([-shift:shift],mean(ROIs(cellnr).segments')-std(ROIs(cellnr).segments')/9,'k')
% 
% plot([0 0],ylim,'r')
% 
% 
% spktimes = makind;
% frametimes = trig;

plot_y_win=50;
plot_y_win_sta=10;

% close all
for cycle = 1:8
    cnt=0;
    fig2 = figure(cycle+465);
    set(fig2,'position',[-1000 100 4000 800],'color','w')%,'menubar','none')
    
    for cellnr = 1+(cycle-1)*10:10*cycle
        cnt=cnt+1;
        
        axes('position', [0,1-0.1*cnt,0.9,0.1])
        hold on
        cut = max(find(spktimes<frametimes(length(frametimes)-50)));
        spkframes = zeros(size(cut));
        for ind = 1:cut
            spkframes(ind) = min(find(frametimes > spktimes(ind)));
        end
        plot(ROIs(cellnr).activity,'k')
        max_y=mean(ROIs(cellnr).activity)+plot_y_win;
        min_y=mean(ROIs(cellnr).activity)-plot_y_win;
        for ind = 1:length(spkframes)
            plot([spkframes(ind) spkframes(ind)],[min_y max_y],'r')
        end
        ylim([min_y max_y])
        text(0,min_y+plot_y_win/5,['Cell nr. ' num2str(cellnr)])
        axis off
        
        axes('position', [0.9,1-0.1*cnt,0.1,0.1])
        max_y=mean(ROIs(cellnr).activity)+plot_y_win_sta;
        min_y=mean(ROIs(cellnr).activity)-plot_y_win_sta;
        plot(smooth(mean(ROIs(cellnr).segments'),3),'k','linewidt',2)
        hold on
        axis tight
        ylim([min_y max_y])
        plot([1 1]*41,[min_y max_y],'k')
        axis off
        
    end
end
























